let blocks = "WBBWWBBWBW"
var minimumRecolors = function(blocks, k) {
    let right = k-1 //右边界
    let left = 0 //左边界
    let min = k //定义一个初始值
    while(right<blocks.length)//定义右边界最终值
        {
        let count = 0
        for(let i=left;i<=right;i++)//遍历区间中的所有元素
            {
            if(blocks[i]=='W') //如果元素为W
                {
                count++
            }
        }
        min = Math.min(min,count)//比较取最小值
        left++ //左边界向右移动
        right++ //右边界向右移动
    }
    return min
};
console.log(minimumRecolors(blocks,7))